package com.zllkj.mm.util.common

import java.math.BigDecimal
import java.text.DecimalFormat
import java.text.SimpleDateFormat
import java.util.*
import java.util.concurrent.TimeUnit

class FormatUtil {
    companion object {
        private fun formatMoney(money:Double):String{
            return DecimalFormat("#0.00").format(money)
        }
        fun bigDecimalUtilFormat(from:String,to:String):String{
            return "¥" +  formatMoney(BigDecimal(from).divide(BigDecimal(to)).toDouble())
        }

        fun formatDurationTime(duration: Long): String {
            return String.format(Locale.getDefault(), "%02d:%02d",
                    TimeUnit.MILLISECONDS.toMinutes(duration), TimeUnit.MILLISECONDS.toSeconds(duration)
                    - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration)))
        }


        fun dataFormat(time:String):String{
            var dataformat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.CHINA)

            var startTime = dataformat.parse(time)

            var startCl = Calendar.getInstance().apply { timeInMillis = startTime.time  }
            var curCl = Calendar.getInstance().apply { timeInMillis = System.currentTimeMillis() }


            if (curCl.get(Calendar.YEAR) == startCl.get(Calendar.YEAR)){//同一年
                var diffDay = curCl.get(Calendar.DAY_OF_YEAR) - startCl.get(Calendar.DAY_OF_YEAR)
                return when {
                    diffDay <= 8 -> {
                        "一周内"
                    }
                    diffDay == 0 -> {
                        "当天"
                    }
                    diffDay == -1 -> {
                        "昨天"
                    }
                    diffDay in 9..15 -> {
                        "两周内"
                    }
                    else -> {
                        "一个月内"
                    }
                }
            } else {
                return "去年"
            }
        }

        fun getAfterSaleOrderStatus(status:Int?):String{
            return when(status){
                1 -> "待卖家确认"
                2 -> "待退货"
                3 -> "待确认收货"
                4 -> "待退款"
                5 -> "退款成功"
                6 -> "售后驳回"
                7 -> "买家取消"
                8 -> "拒绝退款"
                else -> "错误"
            }
        }

        fun getNormalOrderStatus(status:Int):String{
            return when(status){
                1 -> "待付款"
                2 -> "待发货"
                3 -> "待收货"
                4 -> "待评价"
                5 -> "已完成"
                6 -> "已取消"
                7 -> "已关闭"
                else -> "错误"
            }
        }
    }
}